const { knex, TABLE_NAME } = require('./db');

knex.schema
  .hasTable(TABLE_NAME.contract)
  .then(exists => {
    if (!exists) {
      console.log('创建contract表------------------');
      return knex.schema.createTable(TABLE_NAME.contract, t => {
        t.charset('utf8');
        t.uuid('id').primary();
        t.string('FlowId');
        t.string('DocumentId');
        t.string('CallbackType');
        t.string('FlowName');
        t.string('FlowDescription');
        t.string('FlowType');
        t.integer('FlowCallbackStatus');
        t.boolean('Unordered');
        t.integer('CreateOn', 20);
        t.integer('UpdatedOn', 20);
        t.integer('DeadLine', 20);
        t.string('UserId');
        t.string('RecipientId');
        t.string('Operate');
        t.string('UserData');
        t.string('ApproverName');
        t.string('ApproverMobile');
        // t.json('Approvers');
        t.string('CallbackUrl');
        t.string('OrganizationId');
        // t.json('CcInfos');
      });
    }
  })
  .catch(err => {
    console.error({
      message: err.message,
      stack: err.stack,
      Action: 'contract/createTable',
    });
    console.error(err);
  });

// [
//   {
//     FlowId: 'yDwnQUUgygk9jzfvUegbqC9BI4nmrnte',
//     DocumentId: 'yDwnQUUgygk9jzftUegbq8RxhjdXgwif',
//     CallbackType: 'sign',
//     FlowName: '小时工附加协议(1).pdf',
//     FlowDescription: '',
//     FlowType: '',
//     FlowCallbackStatus: 1,
//     Unordered: false,
//     CreateOn: 1679898006,
//     UpdatedOn: 1679898007,
//     DeadLine: 1711434006,
//     UserId: 'yDwnQUUgygk9nz5zUxqWwJS1B8HaVVZW',
//     RecipientId: '',
//     Operate: 'start',
//     UserData: '',
//     Approvers: [
//       {
//         UserId: 'yDR1eUUgygj9be9vUuO4zjEyaxpZzfYG',
//         RecipientId: 'yDwnQUUgygk9jzfyUegbq1o5mzb2tvWy',
//         ApproverType: 1,
//         OrganizationName: '',
//         Required: true,
//         ApproverName: '陈鹏飞',
//         ApproverMobile: '15601997177',
//         ApproverIdCardType: 'ID_CARD',
//         ApproverIdCardNumber: '430722199003173036',
//         ApproveCallbackStatus: 2,
//         ApproveMessage: '',
//         ApproveTime: 0,
//         VerifyChannel: '',
//         CustomUserId: '',
//         ApproverSource: '',
//         CustomApproverTag: '',
//         CaSign: '',
//       },
//     ],
//     CallbackUrl: 'https://ihxdqf-vaiplf-9000.app.myide.io/api/common/callback',
//     OrganizationId: 'yDwnoUUgygktbnu7UubJbk9SFpcrHXGS',
//     CcInfos: [],
//   },
// ];

// {
//   FlowId: 'yDwnQUUgygk9jzfvUegbqC9BI4nmrnte',
//   DocumentId: 'yDwnQUUgygk9jzftUegbq8RxhjdXgwif',
//   CallbackType: 'sign',
//   FlowName: '小时工附加协议(1).pdf',
//   FlowDescription: '',
//   FlowType: '',
//   FlowCallbackStatus: 4,
//   Unordered: false,
//   CreateOn: 1679898006,
//   UpdatedOn: 1679898382,
//   DeadLine: 1711434006,
//   UserId: 'yDwnQUUgygk9nz5zUxqWwJS1B8HaVVZW',
//   RecipientId: 'yDwnQUUgygk9jzfyUegbq1o5mzb2tvWy',
//   Operate: 'sign',
//   UserData: '',
//   Approvers: [
//     {
//       UserId: 'yDR1eUUgygj9be9vUuO4zjEyaxpZzfYG',
//       RecipientId: 'yDwnQUUgygk9jzfyUegbq1o5mzb2tvWy',
//       ApproverType: 1,
//       OrganizationName: '',
//       Required: true,
//       ApproverName: '陈鹏飞',
//       ApproverMobile: '15601997177',
//       ApproverIdCardType: 'ID_CARD',
//       ApproverIdCardNumber: '430722199003173036',
//       ApproveCallbackStatus: 3,
//       ApproveMessage: '',
//       ApproveTime: 1679898382,
//       VerifyChannel: '',
//       CustomUserId: '',
//       ApproverSource: '',
//       CustomApproverTag: '',
//       CaSign: ''
//     }
//   ],
//   CallbackUrl: 'https://ihxdqf-vaiplf-9000.app.myide.io/api/common/callback',
//   OrganizationId: 'yDwnoUUgygktbnu7UubJbk9SFpcrHXGS',
//   CcInfos: []
// }


// {
//   FlowId: 'yDwnQUUgygk9jzfvUegbqC9BI4nmrnte',
//   DocumentId: 'yDwnQUUgygk9jzftUegbq8RxhjdXgwif',
//   CallbackType: 'sign',
//   FlowName: '小时工附加协议(1).pdf',
//   FlowDescription: '',
//   FlowType: '',
//   FlowCallbackStatus: 4,
//   Unordered: false,
//   CreateOn: 1679898006,
//   UpdatedOn: 1679898382,
//   DeadLine: 1711434006,
//   UserId: 'yDwnQUUgygk9nz5zUxqWwJS1B8HaVVZW',
//   RecipientId: 'yDwnQUUgygk9jzfyUegbq1o5mzb2tvWy',
//   Operate: 'finish',
//   UserData: '',
//   Approvers: [
//     {
//       UserId: 'yDR1eUUgygj9be9vUuO4zjEyaxpZzfYG',
//       RecipientId: 'yDwnQUUgygk9jzfyUegbq1o5mzb2tvWy',
//       ApproverType: 1,
//       OrganizationName: '',
//       Required: true,
//       ApproverName: '陈鹏飞',
//       ApproverMobile: '15601997177',
//       ApproverIdCardType: 'ID_CARD',
//       ApproverIdCardNumber: '430722199003173036',
//       ApproveCallbackStatus: 3,
//       ApproveMessage: '',
//       ApproveTime: 1679898382,
//       VerifyChannel: '',
//       CustomUserId: '',
//       ApproverSource: '',
//       CustomApproverTag: '',
//       CaSign: ''
//     }
//   ],
//   CallbackUrl: 'https://ihxdqf-vaiplf-9000.app.myide.io/api/common/callback',
//   OrganizationId: 'yDwnoUUgygktbnu7UubJbk9SFpcrHXGS',
//   CcInfos: []
// }